package com.zou.application.redisTemplate;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import com.zou.application.config.RedisConfig;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = RedisConfig.class)
@ActiveProfiles("local")
public class RedisCommond {
	
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	
	/**
	 * 
	 * <p>Description: 仅清空当前select的库<p>
	 * @Author eyzhai
	 * @date 2019年5月14日
	 * @version 1.0.0    
	 * @return: void
	 */
	@Test
	public void flushDB() {
		 redisTemplate.execute(new RedisCallback<Object>() {

				@Override
				public Object doInRedis(RedisConnection connection) throws DataAccessException {
					connection.flushDb();
	                return "ok";
				}
	        });
	}
	
	/**
	 * 
	 * <p>Description: 全部删除<p>
	 * @Author eyzhai
	 * @date 2019年5月14日
	 * @version 1.0.0    
	 * @return: void
	 */
	@Test
	public void flushAllDB() {
		 redisTemplate.execute(new RedisCallback<Object>() {

				@Override
				public Object doInRedis(RedisConnection connection) throws DataAccessException {
					connection.flushAll();
	                return "ok";
				}
	        });
	}
}
